package algorithm.leetcode.I101to200;

import algorithm.leetcode.TreeNode;

/**
 * 给定一个二叉树，找出其最大深度。
 * 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
 */

public class Q104 {
    public int maxDepth(TreeNode root) {
        return root == null ? 0 : Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
    }


    public static void main(String[] args) {
        TreeNode a = new TreeNode(4), b = new TreeNode(4), c = new TreeNode(3), d = new TreeNode(3), e = new TreeNode(2),
                f = new TreeNode(2), g = new TreeNode(1);
        g.left = e;
        g.right = f;
        e.left = c;
        e.right = d;
        c.left = a;
        c.right = b;
        Q104 ozf = new Q104();
        System.out.println(ozf.maxDepth(a));
    }
}

